﻿@{
    ViewBag.Title = "博客管理";
    ViewBag.Active = "recycle";
}
@section endstyles{
    <link href="~/Plugins/dataTables/css/jquery.dataTables.min.css" rel="stylesheet" />
    <link href="~/Plugins/dataTables/css/dataTables.bootstrap4.css" rel="stylesheet" />
    <style type="text/css">
        .hx-control-label::before,
        .hx-control-label::after {
            top: -0.5rem;
        }
    </style>
}
<div>
    <ol class="breadcrumb hx-bg-dark border-0">
        <li class="breadcrumb-item">后台管理</li>
        <li class="breadcrumb-item active">回收站</li>
    </ol>
    <div class="container-fluid bg-white py-4">
        <table class="table table-bordered table-sm">
            <thead class="thead-light text-center">
                <tr>
                    <th>博客名字</th>
                    <th style="width:65px;">博客类型</th>
                    <th style="width:65px;">系统分类</th>
                    <th style="width:65px;">所属用户</th>
                    <th style="width:35px;">发布</th>
                    <th style="width:120px;">发布日期</th>
                    <th style="width:120px;">删除日期</th>
                    <th style="width:70px;">操作</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
@section scripts{
    <script src="~/Plugins/dataTables/js/jquery.dataTables.js"></script>
    <script src="~/Plugins/dataTables/js/dataTables.bootstrap4.js"></script>
    <script>
        var _hxTable;
        $(function () {
            var className = 'text-center',
                orderable = false;
            _hxTable = $('table').DataTable({
                oLanguage: {
                    sUrl:'/plugins/dataTables/i18n/Chinese.json'
                },
                processing: true,
                serverSide: true,
                ordering: false,
                pagingType: "full_numbers",
                ajax: function (data, callback, settings) {
                    hxCore.ajax('/admin/b/loadrecycle', {
                        data,
                        success: function (data) {
                            callback(data);
                        }
                    })
                },
                columns: [
                    {
                        data: "Title",
                        render: function (data, type, row, meta) {
                            var id = hxCore.toHex(row.Id);
                            return `<a target="_blank" href="/article/${row.UserName}/${id}">${data}</a>`;
                        }
                    },
                    { data: "BlogType.Name", className },
                    { data: "Category.Name", className },
                    { data: "UserName", className },
                    { data: "Publish", className, render: renderCheckbox },
                    { data: "PublishDate", className, },
                    { data: "DeleteTime", className},
                    {
                        data: "Id",
                        className: 'text-center',
                        render: function (data, type, row, meta) {
                            data = hxCore.toHex(data);
                            var del = `<a href= '#' data-id='${data}' class='px-1 btn-op' data-type='remove' title='彻底删除'><i class=" fa fa-remove hx-2x"></i></a>`,
                                revert = `<a href= '#' data-id='${data}' class='px-1 btn-op' data-type='revert' title='还原'><i class=" fa fa-reply hx-2x"></i></a>`;
                            return del + revert;
                        }
                    }
                ]
            });
            function renderCheckbox(data, type, row, meta) {
                var s = ` <div class="custom-control custom-checkbox custom-control-inline">
                                <input type="checkbox" class="custom-control-input"
                                        value="${data}"  ${data === 'Y' ? 'checked' : ''} disabled/>
                                <label class="custom-control-label hx-control-label" >
                                </label>
                            </div>`
                return s;
            }
            $('table').on('click', '.btn-op', function () {
                var $me = $(this),
                    url = '/admin/b/do' + $me.data('type'),
                    hexId = $me.data('id'),
                    title = $me.attr('title');
                alertify.confirm(`确定${title}当前博客?`, function () {
                    hxCore.ajax(url, {
                        data: { hexId },
                        success(data) {
                            if (_hxTable) _hxTable.draw();
                            hxCore.remindSuccess(data);
                        }
                    });
                });

            })
        })
    </script>
}
